package system.imp;

import java.io.DataInputStream;

import java.net.URL;

import framework.core.DBConnection;
import framework.core.ILoginContext;
import framework.core.LogWriter;

/**
 * 
 */
public class ProviderDown {
    
    public void doDown(DBConnection con, ILoginContext loginContext){
        
        
        try {
            LogWriter.info ("Begin to Down Provider Data... ");
            String tResult="";       
            
            DataInputStream dis = null;
            
            String tDay=DateUtil.getNextUpDay(-1);
            //文件下载
            String Name="/" + "BSWZ" + "_Company_"+tDay+".xls";
            
            URL url = new URL("http" + "://" + "192.168.0.25" + "/" + "v3/back/down" + Name);
            
            dis = new DataInputStream(url.openStream());
            
            try{
                //导入商户信息
                tResult=GWFileUploadProcessor.batchImportProvider(dis, con, loginContext);
            }catch(GWException e){
                LogWriter.error(e.getMessage());  

            }
            //从返回的值中取得失败和成功的数据
            String tSuccess= tResult.split("-")[0];
            String tFail= tResult.split("-")[1];
            String tOutputPath = tResult.split("-")[2];
            if(Integer.parseInt(tFail)>0){
                LogWriter.error("Fail down Provider output path: " + tOutputPath);
                LogWriter.error("Fail import Provider count: " + tFail);                
            }
            LogWriter.info("Success import Provider count: " + tSuccess);
        }
        catch (Exception ex) {
            LogWriter.error("下载供应商信息时出错!");
            LogWriter.error(ex.getMessage());
        }
    }

    /**
     * @param args
     */
    public static void main(String[] args) {
    // TODO Auto-generated method stub

    }

}
